Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@ethersproject/bignumber
Advanced tools
@ethersproject/bignumber is a library for handling large numbers in JavaScript, particularly useful in the context of Ethereum and blockchain development. It provides utilities for creating, manipulating, and performing arithmetic operations on big numbers, which are common in blockchain transactions and smart contracts.
Creating Big Numbers
This feature allows you to create big numbers from strings, numbers, or hex values. The example demonstrates creating a BigNumber instance from a string and converting it back to a string for display.
const { BigNumber } = require('@ethersproject/bignumber');
const bigNumber = BigNumber.from('12345678901234567890');
console.log(bigNumber.toString());
Arithmetic Operations
This feature provides methods for performing arithmetic operations such as addition, subtraction, multiplication, and division on BigNumber instances. The example shows how to add two BigNumber instances.
const { BigNumber } = require('@ethersproject/bignumber');
const a = BigNumber.from(10);
const b = BigNumber.from(20);
const sum = a.add(b);
console.log(sum.toString());
Comparison Operations
This feature includes methods for comparing BigNumber instances, such as less than (lt), greater than (gt), and equals (eq). The example demonstrates comparing two BigNumber instances.
const { BigNumber } = require('@ethersproject/bignumber');
const a = BigNumber.from(10);
const b = BigNumber.from(20);
console.log(a.lt(b)); // true
console.log(a.eq(b)); // false
Formatting and Parsing
This feature allows you to format BigNumber instances to different string representations, such as hexadecimal. The example shows how to convert a BigNumber to a hex string.
const { BigNumber } = require('@ethersproject/bignumber');
const bigNumber = BigNumber.from('12345678901234567890');
const formatted = bigNumber.toHexString();
console.log(formatted);
bignumber.js is a popular library for arbitrary-precision decimal and non-decimal arithmetic in JavaScript. It provides similar functionality to @ethersproject/bignumber but is more general-purpose and not specifically tailored for Ethereum or blockchain development.
bn.js is a library for arbitrary-precision arithmetic in JavaScript. It is widely used in cryptographic applications and provides a comprehensive set of methods for working with large integers. Compared to @ethersproject/bignumber, bn.js is more focused on performance and low-level operations.
decimal.js is a library for arbitrary-precision decimal arithmetic in JavaScript. It is similar to bignumber.js but focuses on decimal numbers rather than integers. It provides a rich set of methods for mathematical operations and is suitable for financial calculations.
This sub-module is part of the ethers project.
It is responsible for handling arbitrarily large numbers and mathematic operations.
For more information, see the documentation for Big Numbers and Fixed-Point Numbers.
Most users will prefer to use the umbrella package, but for those with more specific needs, individual components can be imported.
const {
BigNumber,
FixedFormat,
FixedNumber,
formatFixed,
parseFixed
// Types
BigNumberish
} = require("@ethersproject/bignumber");
MIT License
FAQs
BigNumber library used in ethers.js.
The npm package @ethersproject/bignumber receives a total of 828,081 weekly downloads. As such, @ethersproject/bignumber popularity was classified as popular.
We found that @ethersproject/bignumber demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.